IMGFILE=../HD.IMG
#8*16*63=8046
dd if=/dev/zero of=$IMGFILE bs=512 count=8064
sudo losetup /dev/loop0 $IMGFILE
echo '+-----------------------------------------+'
echo '| INPUT: o n p 1 <return> <return> a 1 p w|'
echo '+-----------------------------------------+'
sudo fdisk -u -C8 -H16 -S63 /dev/loop0
sudo losetup -d /dev/loop0

echo 'Making File System'
sudo losetup -o32256 /dev/loop1 $IMGFILE
sudo mkfs /dev/loop1

echo 'Coping Grub Files'
sudo mount /dev/loop1 /mnt
sudo mkdir -p /mnt/boot/grub
sudo cp /boot/grub/* /mnt/boot/grub/
sudo cp grub.conf /mnt/boot/grub/
sudo sync
sudo umount /mnt
sudo losetup -d /dev/loop1


echo '+------------------------------------------+'
echo '| Install Grub:                            |'
echo '| 1. device (hd0) /dev/loop3               |'
echo '| 2. root (hd0,0)                          |'
echo '| 3. setup --stage2=/boot/grub/stage2 (hd0)|'
echo '| 4. quit                                  |'
echo '+------------------------------------------+'
sudo losetup /dev/loop3 $IMGFILE
sudo grub
sudo losetup -d /dev/loop3
sudo grub-install /dev/sda

echo '+------------------------------------------+'
echo '| rember to execute these commands in grub |'
echo '| root(hd0,0)                              |'
echo '| setup (hd0)                              |'
echo '+------------------------------------------+'
